// Copyright (C) 2016 All rights reserved.
// Author: liufeng11@letv.com (Liu Feng)
// Description:

#include "Similarity.h"
#include <cmath>
#include <cstdio>
#include <cstdlib>


double Similarity::GetSimilarity(const std::vector<double>& feature1, const std::vector<double>& feature2) {
  return GetEuclideanDistance(feature1, feature2);
}

double Similarity::operator()(const std::vector<double>& feature1, const std::vector<double>& feature2) {
  return GetSimilarity(feature1, feature2);
}

double Similarity::GetEuclideanDistance(const std::vector<double>& feature1, const std::vector<double>& feature2) {
  if (feature1.size() != feature2.size()) {
    printf("%s:%d : %s\n", __FILE__, __LINE__, __FUNCTION__);
    printf("feature1 dim: %d, feature2 dim: %d\n", feature1.size(), feature2.size());
    exit(-1);
  }

  int length = feature1.size();
  double sum = 0; 
  for (int i = 0; i < length; ++i) {
    double diff = feature1[i] - feature2[i];
    sum += diff * diff;
  }

  return sqrt(sum);
}

